import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_controller_lifecycle/4%E3%80%81Get.put%E5%92%8CGet.to%E5%90%8C%E4%B8%80%E4%B8%AA%E7%B1%BB%E4%B8%8D%E5%90%8C%E5%AE%9E%E4%BE%8B/put_same_class_detail_controller.dart';

class PutSameClassDetailPage extends StatelessWidget {
  const PutSameClassDetailPage({Key? key, required this.model}) : super(key: key);

  final PutSameClassController model;

  void toDetailPage1() {
    PutSameClassController model = PutSameClassController.randomInstance();
    Get.to(() => PutSameClassDetailPage(model: model,));
  }

  void toDetailPage2() {
    PutSameClassController model = PutSameClassController.randomInstance();
    Get.to(() => PutSameClassDetailPage(model: model,), preventDuplicates: false);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(
            "详情页${model.id}",
            style: const TextStyle(
                fontSize: 14
            ),
          ),
        ),
        backgroundColor: Colors.white,
        body: SingleChildScrollView(
          child: Column(
            children: [
              const Padding(
                padding: EdgeInsets.all(15),
                child: Text(
                  """

                  """,
                  maxLines: 100,
                  style: TextStyle(
                    fontSize: 15,
                  ),
                  strutStyle: StrutStyle(
                      leading: 0
                  ),
                ),
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  const Text("Get.to preventDuplicates=true无法跳转相同路由名的页面"),
                  ElevatedButton(onPressed: toDetailPage1, child: const Text("跳转1")),
                  const Text("Get.to preventDuplicates=false可以跳转相同路由名的页面"),
                  ElevatedButton(onPressed: toDetailPage2, child: const Text("跳转2")),
                ],
              ),
            ],
          ),
        )
    );
  }
}
